package t4;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import t4bean.PurchaseDateBean;
import t4bean.PurchaseOrderBean;
import t4bean.SalesvolumDateBean;
import t4bean.SalesvolumeRecordBean;
import t4bean.StallBean;
import t4bean.StockBean;

public class Serialize {
	public void serialize(StallBean stall) throws IOException {
		FileOutputStream fos = new FileOutputStream("D:\\study\\T\\stall.txt");

		List<StockBean> stockList = stall.getStockList();
		List<PurchaseOrderBean> purList = stall.getPurList();
		List<SalesvolumeRecordBean> salList = stall.getSalList();
		List<PurchaseDateBean> purDateList = stall.getPurDateList();
		List<SalesvolumDateBean> salDateList = stall.getSalDateList();

		for (StockBean sto : stockList) {
			fos.write(String.valueOf(sto.getStockNumber()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(sto.getFruit().getCost()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(sto.getFruit().getPrice()).getBytes());
			fos.write("\n".getBytes());
			fos.write(sto.getFruit().getName().getBytes());
			fos.write("\n".getBytes());
		}
		fos.write("\n".getBytes());
		for (PurchaseOrderBean pur : purList) {
			fos.write(String.valueOf(pur.getFruit().getCost()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(pur.getFruit().getPrice()).getBytes());
			fos.write("\n".getBytes());
			fos.write(pur.getFruit().getName().getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(pur.getPurchaseQuantity()).getBytes());
			fos.write("\n".getBytes());
		}
		fos.write("\n".getBytes());
		for (SalesvolumeRecordBean sal : salList) {
			fos.write(String.valueOf(sal.getDiscount()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(sal.getFruit().getCost()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(sal.getFruit().getPrice()).getBytes());
			fos.write("\n".getBytes());
			fos.write(sal.getFruit().getName().getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(sal.getSalesVolume()).getBytes());
			fos.write("\n".getBytes());
		}
		fos.write("\n".getBytes());
		for (PurchaseDateBean purDate : purDateList) {
			fos.write(String.valueOf(purDate.getDay()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(purDate.getMonth()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(purDate.getFruit().getCost()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(purDate.getFruit().getPrice()).getBytes());
			fos.write("\n".getBytes());
			fos.write(purDate.getFruit().getName().getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(purDate.getPo().getPurchaseQuantity()).getBytes());
			fos.write("\n".getBytes());
		}
		fos.write("\n".getBytes());
		for (SalesvolumDateBean salDate : salDateList) {
			fos.write(String.valueOf(salDate.getDay()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(salDate.getMonth()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(salDate.getFruit().getCost()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(salDate.getFruit().getPrice()).getBytes());
			fos.write("\n".getBytes());
			fos.write(salDate.getFruit().getName().getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(salDate.getSr().getDiscount()).getBytes());
			fos.write("\n".getBytes());
			fos.write(String.valueOf(salDate.getSr().getSalesVolume()).getBytes());
			fos.write("\n".getBytes());
		}
		fos.write("\n".getBytes());
		fos.close();
	}
}
